from django.contrib import admin
from .models import DailyWorkProject, DailyWorkItem

class DailyWorkItemInline(admin.TabularInline):
    model = DailyWorkItem
    extra = 1
    fields = ['content', 'responsible', 'participants', 'order']
    ordering = ['order']

@admin.register(DailyWorkProject)
class DailyWorkProjectAdmin(admin.ModelAdmin):
    list_display = ['date', 'experiment_type', 'project_name', 'duty_day', 'duty_night', 'created_at']
    list_filter = ['experiment_type', 'date', 'created_at']
    search_fields = ['project_name', 'duty_day', 'duty_night']
    date_hierarchy = 'date'
    ordering = ['-date', 'experiment_type', 'order']
    inlines = [DailyWorkItemInline]
    
    fieldsets = (
        ('基本信息', {
            'fields': ('date', 'experiment_type', 'project_name', 'order')
        }),
        ('值班信息', {
            'fields': ('duty_day', 'duty_night'),
            'classes': ('collapse',),
        }),
    )

@admin.register(DailyWorkItem)
class DailyWorkItemAdmin(admin.ModelAdmin):
    list_display = ['project', 'content', 'responsible', 'participants', 'order', 'created_at']
    list_filter = ['project__experiment_type', 'project__date', 'created_at']
    search_fields = ['content', 'responsible', 'participants']
    ordering = ['project__date', 'project__experiment_type', 'project__order', 'order']
